#include "Controller.h"

void updateControl(Control* control, SDL_Event event){
	control->key_button = NONE;
	control->mvt = STATIC;
	control->mouse_button = NONE;


        switch(event.type){
                case SDL_QUIT:
                        control->key_button = ESC;
                        break;
                case SDL_KEYDOWN:
                        switch(event.key.keysym.sym)
                        {
                                case SDLK_UP:
                                        control->key_button = UP;
                                        break;
                                case SDLK_DOWN:
                                        control->key_button = DOWN;
                                        break;
				case SDLK_LEFT:
					control->key_button = LEFT;
					break;
				case SDLK_RIGHT:
					control->key_button = RIGHT;
					break;
                                case SDLK_RETURN:
                                        control->key_button = ENTER;
                                        break;
                                case SDLK_SPACE:
                                        control->key_button = SPACE;
                                        break;
				case SDLK_ESCAPE:
					control->key_button = ESC;
					break;
                        }
                        break;
                case SDL_MOUSEBUTTONDOWN:
                        switch(event.button.button){
                                case SDL_BUTTON_LEFT:
                                        control->mouse_button = LEFT;
                                        break;
                                case SDL_BUTTON_RIGHT:
                                        control->mouse_button = RIGHT;
                                        break;
				default : 
					control->mouse_button = NONE;
                        }
			control->mouse_button_coor.x = event.button.x;
			control->mouse_button_coor.y = event.button.y;
			control->state = PRESSED;
			break;
		case SDL_MOUSEBUTTONUP:
			control->mouse_button_coor.x = event.button.x;
			control->mouse_button_coor.y = event.button.y;
			control->state = RELEASED;
			break;
                case SDL_MOUSEMOTION:
			control->mouse_button_coor.x = event.button.x;
			control->mouse_button_coor.y = event.button.y;
                        control->mvt = MOTION;
        }
}

void getEvent(Control* control){
	SDL_Event event;

	SDL_PollEvent(&event);
	updateControl(control, event);
}
